#!/usr/bin/env python
#!conding:utf-8
"""
author:Johnson
date: 2017/5/16 14:44
version: v1.0
description:
    models
"""
from blog import db, app


def get_all(sql,param = None):
    try:
        if param != None:
            data = db.session.execute(sql,param).fetchall()
        else:
            data = db.session.execute(sql).fetchall()
    except Exception as e:
        app.logger.exception(e,exc_info = True)
    return data


def get_by_id(sql,param):
    return db.session.execute(str(sql),param).first()

def execute(sql,param):
    try:
        db.session.execute(sql,param)
        app.logger.debug("sql--> {} , param --> {}".format(sql,param))
    except Exception as e:
        app.logger.exception(e,exc_info = True)     #非error级别的异常也会被打印exc_info = True

